<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateOriginalPlanNodeTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function up()
    {
        $table = $this->table('original_plan_node', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '原计划排期节点表']);
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('tenant_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '租户ID'])
            ->addColumn('project_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '项目id'])
            ->addColumn('episode_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '剧集id'])
            ->addColumn('name', 'string', ['limit' => 256, 'null' => false, 'default' => '', 'comment' => '名称'])
            ->addColumn('delivery_time', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '交付时间'])
            ->addColumn('step_category_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '环节ID'])
            ->addColumn('stage_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '阶段ID'])
            ->addColumn('type', 'integer', ['limit' => 255, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '类型：1=标准排期 2=组内排期 3=标准需求 4=非标需求 5=延期 6=工单'])
            ->addColumn('link_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '排期ID｜需求ID｜延期单ID ｜ 工单ID'])
            ->addColumn('all_task_ids', 'text', ['null' => true, 'comment' => '任务ID集合：以,拼接'])
            ->addColumn('delivery_task_ids', 'text', ['null' => true, 'comment' => '交付任务ID集合：以,拼接'])
            ->addColumn('all_entity_ids', 'text', ['null' => true, 'comment' => '所有实体ID集合 以,拼接'])
            ->addColumn('delivery_entity_ids', 'text', ['null' => true, 'comment' => '交付实体ID集合 以,拼接'])
            ->addColumn('deprecated_task_ids', 'string', ['default' => '', 'limit' => 255, 'comment' => '废除任务ids'])
            ->addColumn('deprecated_entity_ids', 'string', ['default' => '', 'limit' => 255, 'comment' => '废除实体ids'])
            ->addColumn('status', 'integer', ['limit' => 255, 'null' => false, 'signed' => false, 'default' => 1, 'comment' => '状态：1=未执行  2=已执行'])
            ->addColumn('created', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '创建时间'])
            ->addColumn('created_by', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '创建者'])
            ->addIndex(['delivery_time', 'status'], ['type' => 'normal', 'name' => 'delivery_status'])
            ->addIndex(['project_id', 'episode_id'], ['type' => 'normal', 'name' => 'project_episode']);
        // 创建表
        $table->create();
    }

    public function down()
    {
        $this->table('original_plan_node')->drop()->save();
    }
}
